package com.wt.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author hiberk
 * Date 2017/7/4 10:16
 * 将Integer或者Long转成jsp页面的指定格式时间
 */
public class SQLTypeOnJsp extends TagSupport implements Serializable{

    private static final long serialVersionUID = -2305721744298666630L;
    private String pattern;
    private Long msvalue; //毫秒
    private Long mValue;//秒级别的数据  因为要乘以1000  所有用Long来接受。否则会溢出导致接受结果不正确

    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public Long getMsvalue() {
        return msvalue;
    }

    public void setMsvalue(Long msvalue) {
        this.msvalue = msvalue;
    }

    public Long getmValue() {
        return mValue;
    }

    public void setmValue(Long mValue) {
        this.mValue = mValue;
    }

    @Override
    public int doEndTag() throws JspException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = new Date(msvalue == null ? mValue*1000 : msvalue);
        String out = simpleDateFormat.format(date);
        try {
            this.pageContext.getOut().print(out.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return super.doEndTag();
    }
}

